# Contributor: knuxify <knuxify@gmail.com>
# Maintainer: knuxify <knuxify@gmail.com>
pkgname=font-manager
_viewer_pkgname=font-viewer
pkgver=0.8.8
pkgrel=6
pkgdesc="Simple font management application for GTK Desktop Environments"
url="https://fontmanager.github.io/"
arch="all"
license="GPL-3.0-or-later"
depends_doc="yelp"
makedepends="meson
	freetype-dev
	glib-dev
	gobject-introspection-dev
	gtk+3.0-dev
	itstool
	json-glib-dev
	libxml2-dev
	webkit2gtk-4.1-dev
	yelp-tools
	vala"
# For file manager extentions
makedepends="$makedepends thunar-dev"
subpackages="$pkgname-doc
	$pkgname-lang
	$pkgname-common:common
	$_viewer_pkgname:font_viewer
	$pkgname-thunar:ext_thunar"

case "$CARCH" in
	s390x|ppc64le|riscv64)
		_enable_nemo=false
		_enable_nautilus=false
		;;
	*)
		makedepends="$makedepends nemo-dev nautilus-dev"
		subpackages="$subpackages
					$pkgname-nemo:ext_nemo"
		_enable_nemo=true
		# todo
		_enable_nautilus=false
		;;
esac

source="https://github.com/FontManager/font-manager/releases/download/$pkgver/font-manager-$pkgver.tar.xz
	libsoup3.patch
	"
options="!check" # no test suite, see https://github.com/FontManager/font-manager/issues/238

build() {
	abuild-meson \
		-Db_lto=true \
		-Dnautilus=$_enable_nautilus \
		-Dnemo=$_enable_nemo \
		-Dthunar=true \
		-Dreproducible=true \
		. output
	meson compile -C output
}

check() {
	meson test --no-rebuild --print-errorlogs -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
}

common() {
	pkgdesc="Common files/libraries for font-manager and font-viewer"
	amove usr/lib/font-manager
}

font_viewer() {
	pkgdesc="Full featured font file preview application for GTK+ Desktop Environments"
	local pkgid="org.gnome.FontViewer"

	amove usr/libexec/font-manager
	amove usr/share/applications/$pkgid.desktop
	amove usr/share/dbus-1/services/$pkgid.service
	amove usr/share/glib-*/schemas/$pkgid.gschema.xml
	amove usr/share/icons/hicolor/*/apps/$pkgid.png
	amove usr/share/metainfo/$pkgid.appdata.xml
}

ext_nautilus() {
	pkgdesc="Nautilus file manager extension for font-manager"
	install_if="font-manager=$pkgver-r$pkgrel nautilus"

	amove usr/lib/nautilus/extensions-3.0/nautilus-font-manager.so
}

ext_nemo() {
	pkgdesc="Nemo file manager extension for font-manager"
	install_if="font-manager=$pkgver-r$pkgrel nemo"

	amove usr/lib/nemo/extensions-3.0/nemo-font-manager.so
}

ext_thunar() {
	pkgdesc="Thunar file manager extension for font-manager"
	install_if="font-manager=$pkgver-r$pkgrel thunar"

	amove usr/lib/thunarx-3/thunar-font-manager.so
}

sha512sums="
75e85af8bbbac4f4f3e73371eb618e75afdd14ea1dc1eab7855db537356c4a9f89121554db2c7a7e2a2357a545a6c2ad69bebbde4ed588a6f9ec0bfe1cc67ad0  font-manager-0.8.8.tar.xz
3d31661695ef31e2f86c613ca68a1740e133b8799579d71224df32d3302a1cd665eab099a4e3aad4e969074221e6c587f2b09dec2cdaf1cce013521b59282b8e  libsoup3.patch
"
